<?php
/**
 * Punny - The most easy-to-use PHP MVC framework
 * 
 * Copyright (c) 2010  
 *
 * @author email :lx.xin@qq.com
 */
 class Comment extends Base{
	protected $_name='my_comment';
	protected $_parmary='id';
	
	/*
	 *添加评论
	 */
	function addComment($data){
		return $this->insert($data);
	}
	/*
	 *根据blogid查询评论
	 */
	 function queryComment($id){
		$data=$this->fetchAll("ishidden=0 and blogid='$id'")->toArray();
		return $data;
	 }
	 /*
	  *获取最近5条评论
	  */
	  function getComment(){
		$data=$this->fetchAll(null,'posttime DESC',5)->toArray();		
		$array=array();
		foreach($data as $key=>$val){
			$array[$key]['blogid']=$val['blogid'];
			$array[$key]['posttime']=$val['posttime'];
			$array[$key]['content']=$val['content'];
		}		
		return $array;
	  }
	  /*
	   *获取所有评论
	   */
	   function getAllComment(){
		$data=$this->fetchAll()->toArray();
		return $data;
	   }
	   /*
	    *删除评论
		*/
		function delComment($id){
			$db=$this->getAdapter();
			$where=$db->quoteInto('id = ?',$id);
			return $this->delete($where);
		}
		/*
		 *评论数
		 */
		 function commentNums(){
			$num=$this->fetchAll()->count();
			return $num;
		 }
 }






 ?>